package aboutme.felipesilvestre.oracaolista.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import aboutme.felipesilvestre.oracaolista.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class CategoriaAdapter extends SimpleAdapter {

	Context ctx;
	
    public CategoriaAdapter(Context context, List<? extends Map<String, ?>> data,
            int resource, String[] from, int[] to) {
        super(context, data, resource, from, to);
        
        this.ctx = context;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = ((LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.spinnerlayout,
                    null);
        }

        HashMap<String, Object> data = (HashMap<String, Object>) getItem(position);

        ((TextView) convertView.findViewById(R.id.spNomeCateg))
                .setText((String) data.get("Name"));
        ((ImageView) convertView.findViewById(R.id.spImgCateg))
                .setImageResource((Integer) data.get("Icon"));

        return convertView;
    }

}